#include "reopen"
#include <iostream>
#include <string.h>
using namespace std;

int main(void) {
  reopen("1759");
  int a[5005];
  int d[5005];
  memset(d, 0, sizeof(d));
  int n = 0, m = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  a[n] = 1000001;
  for (int i = n - 1; i >= 0; i--) {
    for (int j = i + 1; j <= n; j++) {
      if (a[i] < a[j] && d[i] < d[j])
        d[i] = d[j];
    }
    d[i] += 1;
  }
  for (int i = 0; i < n; i++) {
    if (m < d[i])
      m = d[i];
  }
  cout<<m;
  return 0;
}
